﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Base.cshtml";
}
<table border="0" width="100%">
    <tr>
        <td valign="middle" align="left" width="200px">
            <span style="font-size: 14px">会员类型:</span><select id="ddlType" name="ddlType" class="selectpicker"
                data-style="btn-info" data-width="100px" style="margin-top: 10px">
                <option value="-1">全部</option>
                <option value="1">投资人</option>
                <option value="2">借款人</option>
            </select>
        </td>
        <td valign="middle" align="left" width="200px">
            <span style="font-size: 14px">是否激活:</span><select id="ddlActive" name="ddlActive"
                class="selectpicker" data-style="btn-info" data-width="100px">
                <option value="-1">全部</option>
                <option value="1">已激活</option>
                <option value="0">未激活</option>
            </select>
        </td>
        <td valign="middle" align="left" width="350px">
            <span style="font-size: 14px">关键字:</span>
            <input id="txtKey" name="txtKey" type="text" class="input-medium search-query" placeholder="用户名/姓名/手机/Email"
                style="width: 250px; background-color: #fff;" />
        </td>
        <td valign="middle" align="left">
            <button class="btn btn-primary btn-small" id="btnSearch">
                查询
            </button>
        </td>
    </tr>
</table>
<div style="width: 99%; height: 1px; overflow: hidden; background-color: #dddddd;
    margin: 6px">
</div>
<table id="membergrid" class="mmg">
    <tr>
        <th rowspan="" colspan="">
        </th>
    </tr>
</table>
<div id="pg" style="text-align: right;">
</div>
@section tail{
    <script src="/content/plugins/mmgrid/mmGrid.js" type="text/javascript"></script>
    <script src="/content/plugins/mmgrid/mmPaginator.js" type="text/javascript"></script>
    @*<script src="/content/plugins/bootbox.min.js"></script>*@
    <script type="text/javascript">

        var cols = [

        { title: '用户名', name: 'UserName', width: 150, align: 'center' },
        { title: '真实姓名', name: 'RealName', width: 60, align: 'center' },
        { title: '身份证号', name: 'IDCardNo', width: 120, align: 'center' },
        { title: '手机', name: 'HandPhone', width: 80, align: 'center' },
        { title: '邮箱', name: 'Email', width: 150, align: 'center' },
        { title: '类型', name: 'MemberType', width: 40, align: 'center', renderer: function (val, item, index) {
            if (item["MemberType"] == 1) return '投资人';
            else if (item["MemberType"] == 2) return '借款人';
            return '未知';
        }
        },
        { title: '是否激活', name: 'IsActive', width: 50, align: 'center', renderer: function (val, item, index) {
            if (item["IsActive"]) return '已激活';
            return '未激活';
        }
        },
        { title: '状态', name: 'Status', width: 30, align: 'center', renderer: function (val, item, index) {

            if (val == 0) return '禁用';
            return '正常';
        }
        },
        { title: '操作', name: 'UserName', width: 150, align: 'center', lockWidth: true, lockDisplay: true, renderer: function (val, item, index) {
            var html = "";

            html = '<button class="btn btn-info btn-mini" onclick="grid_memeber_view(\'' + item["UserName"] + '\')">详细</button>';
            if (item['Status'] == 1) {
                html += ' <button  class="btn btn-info btn-mini" onclick="grid_member_changestate(\'' + item["UserName"] + '\',0)">禁用</button>';
            }
            else {
                html += ' <button  class="btn btn-info btn-mini" onclick="grid_member_changestate(\'' + item["UserName"] + '\',1)">启用</button>';
            }

            return html;
        }
        }
    ];

        var mmg;
        var ddlType;
        var ddlActive;
        $(function () {
            ddlType = $("#ddlType").selectpicker('show');
            ddlActive = $("#ddlActive").selectpicker('show');
            mmg = $('#membergrid').mmGrid({
                indexCol: true,
                indexColWidth: 25,
                height: $("body", parent.document).height() - 245,
                cols: cols,
                url: '/Member/GetMemberListByPage',
                method: 'get',
                remoteSort: true,
                //items: items,
                //sortName: 'SECUCODE',
                //sortStatus: 'asc',
                multiSelect: false,
                checkCol: false,
                fullWidthRows: true,
                autoLoad: false,
                plugins: [
                        $('#pg').mmPaginator()
                    ]
            });
            mmg.load();
            $("#btnSearch").click(function () {

                search();

            });
        });

        function search() {
            mmg.setParm({ keyword: $("#txtKey").val(), memberType: ddlType.val(), activeStatus: ddlActive.val() });
            mmg.load({ page: 1 });
        }


        function grid_member_changestate(userName, state) {

            var statestr = "禁用";
            if (state == 1) {
                statestr = "启用";
            }

            bootbox.confirm("<span style='font-size:14px;'><i style='color:green;' class='icon-question-sign bigger-290'></i> &nbsp;&nbsp;确定要" + statestr + "该会员吗？</span>", '300px', function (confirmed) {
                if (confirmed == true) {
                    $.ajax({
                        url: "/Member/MemberChangeStatus",
                        data: "userName=" + userName + "&status=" + state,
                        type: "post",
                        cache: false,
                        success: function (result) {

                            if (result == "1") {
                                bootbox.alert("<span style='font-size:14px;'><i style='color:green;' class='icon-ok-sign bigger-290'></i>&nbsp;&nbsp;" + statestr + "会员成功</span>", '300px');
                                mmg.load();
                            } else {
                                bootbox.alert("<span style='font-size:14px;'><i style='color:green;' class='icon-remove-sign bigger-290'></i>&nbsp;&nbsp;" + statestr + "会员失败</span>", '300px');

                            }
                        }
                    });
                }
            });

        }

        function grid_memeber_view(userName) {
            location.href = decodeURIComponent("/Member/MemeberDetail?userName=" + userName + "&backUrl=/Member/Index");
        }
         
    </script>
}
